package com.ohos.carbon.slice.themes.bottom;

import com.ohos.carbon.ResourceTable;
import ohos.app.Context;

import java.util.ArrayList;
import java.util.List;

/**
 * 业务逻辑放到这个类来做
 *
 */
public class MainAbilitySlicePresenter {

    private AbilitySliceProvider mAbilitySliceProvider;
    /**
     * 底部导航栏的数据
     */
    private List<BottomBarInfo<?>> bottomInfoList;
    /**
     * 底部导航栏
     */
    private BottomNavigationBar tabBottomLayout;

    private Context mContext;


    public MainAbilitySlicePresenter(AbilitySliceProvider abilitySliceProvider) {
        mAbilitySliceProvider = abilitySliceProvider;
        mContext = abilitySliceProvider.getContext();

        initBottom();
    }

    private void initBottom() {
        tabBottomLayout = (BottomNavigationBar) mAbilitySliceProvider.findComponentById(ResourceTable.Id_bottom_navigation_bar);
        bottomInfoList = new ArrayList<>();
        //获取color.json文件中定义的颜色值
        int defaultColor = mAbilitySliceProvider.getColor(ResourceTable.Color_default_color);
        int tintColor = mAbilitySliceProvider.getColor(ResourceTable.Color_tint_color);

        // 获取string.json文件中定义的字符串
        String news = mAbilitySliceProvider.getString(ResourceTable.String_news);
        String mail = mAbilitySliceProvider.getString(ResourceTable.String_mail);
        String profile = mAbilitySliceProvider.getString(ResourceTable.String_profile);

        BottomBarInfo<Integer> newsInfo = new BottomBarInfo<>(news,
                ResourceTable.Media_news_normal,
                ResourceTable.Media_news_selected,
                defaultColor, tintColor);

        BottomBarInfo<Integer> mailInfo = new BottomBarInfo<>(mail,
                ResourceTable.Media_mail_normal,
                ResourceTable.Media_mail_selected,
                defaultColor, tintColor);

        BottomBarInfo<Integer> profileInfo = new BottomBarInfo<>(profile,
                ResourceTable.Media_profile_normal,
                ResourceTable.Media_profile_selected,
                defaultColor, tintColor);

        // 将每个条目的数据放入到集合
        bottomInfoList.add(newsInfo);
        bottomInfoList.add(mailInfo);
        bottomInfoList.add(profileInfo);
        // 设置底部导航栏的透明度
        tabBottomLayout.setBarBottomAlpha(0.85f);
        // 初始化所有的条目
        tabBottomLayout.initInfo(bottomInfoList);

        tabBottomLayout.defaultSelected(newsInfo);

    }

}
